<?php
defined('THINK_PATH') or exit();
class TagLibEt extends TagLib{
    // 标签定义
    protected $tags   =  array(
        // 标签定义： attr 属性列表 close 是否闭合（0 或者1 默认1） alias 标签别名 level 嵌套层次
    	
    	/*栏目标签*/	
		'topcates'     => array('attr'=>'json,lang,limit,delim,lclass,aclass,idclass,isnav','close'=>0),
        'levelcates'   => array('attr'=>'json,lang,module,cateid,level,delim,action,lclass,aclass,idclass','close'=>0),
        'category'     => array('attr'=>'json,lang,cateid,childs,module,limit,hover,isnav,delim,action,lclass,aclass,idclass','close'=>0),
		'position'     => array('attr'=>'cateid,lang,module,action','close'=>0),
		
		/*列表标签*/
		'list'         => array('attr'=>'where,lang,cateid,module,thumb,single,titlelen,infolen,timeformat,imgwidth,imgheight,orderby,pagesize','close'=>1),
    	'product'      => array('attr'=>'lang,cateid,status,normal,module,thumb,single,titlelen,infolen,timeformat,imgwidth,imgheight,orderby,pagesize','close'=>1),
    	'flagproduct'  => array('attr'=>'lang,cateid,status,normal,module,thumb,single,titlelen,infolen,timeformat,imgwidth,imgheight,orderby,limit','close'=>1),
    	'activity'     => array('attr'=>'lang,view,thumb,single,titlelen,infolen,timeformat,imgwidth,imgheight,orderby,pagesize','close'=>1),
    	'flaglist'     => array('attr'=>'where,lang,cateid,module,thumb,single,titlelen,infolen,timeformat,imgwidth,imgheight,orderby,limit','close'=>1),
      //'artlist'      => array('attr'=>'lang,cateid,module,thumb,single,titlelen,infolen,imgwidth,imgheight,orderby,limit','close'=>1),
    	'pagelist'     => array('attr'=>'themes','close'=>0),
      //'flink'        => array('attr'=>'lang,thumb,single,limit','close'=>1),
    	'admarket'     => array('attr'=>'lang,cateid,columnid,limit,single,imgwidth,imgheight','close'=>1),
    	'relation'     => array('attr'=>'id,module,relation,thumb,single,titlelen,infolen,timeformat,imgwidth,imgheight,orderby,limit','close'=>1),
		
		/*内容标签*/
		'single'       => array('attr'=>'id,module,single,imgwidth,imgheight','close'=>1),
		'atlas'        => array('attr'=>'id,module,atlas','close'=>1),
    	'block'		   => array('attr'=>'lang,key','close'=>0),
		'prev'         => array('attr'=>'module,lang,action,cateid,orderby','close'=>0),
		'next'         => array('attr'=>'module,lang,action,cateid,orderby','close'=>0),
		'detail'       => array('attr'=>'cateid,id,module,thumb,single,where,atlas,imgwidth,imgheight','close'=>1),//詳情标签
	  //'artonce'      => array('attr'=>'cateid,id,thumb,where','close'=>1),//詳情标签
		
		'webtitle'     => array('attr'=>'cateid,id,module','close'=>0),
		'keywords'     => array('attr'=>'cateid,id,module','close'=>0),
		'description'  => array('attr'=>'cateid,id,module','close'=>0),
		'webmeta'      => array('attr'=>'cateid,id,module','close'=>0),
    );
	
	//一级栏目标签
	public function _topcates ($attr, $content) {
		
		$attr    = $this->parseXmlAttr($attr,'topcates');
		$json    = isset($attr['json'])   ? $attr['json']    : false ;
		$isnav   = isset($attr['isnav'])  ? $attr['isnav']   : false ;
		$delim   = isset($attr['delim'])  ? $attr['delim']   : false ;
		$limit   = isset($attr['limit'])  ? $attr['limit']   : "" ;
		$aclass  = isset($attr['aclass']) ? $attr['aclass']  : "" ;
		$lclass  = isset($attr['lclass']) ? $attr['lclass']  : "" ;
		$idclass = isset($attr['idclass'])? $attr['idclass'] : "" ;
		
		$lang    = isset($attr['lang'])  ? $attr['lang'] : getLang();
		$lists   = F('cate_'.$lang);
		$cateid  = I("param.cateid",0,"intval");
		if($cateid){
			$nid = sonFindFather($cateid) ;
		}else{
			foreach($lists as $v){
				if(($v['level']==1) && ($v['pid']==0)){
					$nid = $v["id"];break;
				}
			}
		}
		
		$_rows   = array();
		$_i      = 0 ;
		if($isnav){
			foreach($lists as $v){
				if(($v['level']==1) && ($v['pid']== 0) && ($v['isnav'] == $isnav)){
					$_rows[] = $v ; $_i++ ;
					if($limit){
						if($_i>=$limit)break;
					}
				}
			}
		}else{
			foreach($lists as $v){
				if(($v['level']==1) && ($v['pid']==0)){
					$_rows[] = $v ; $_i++ ;
					if($limit){
						if($_i>=$limit)break;
					}
				}
			}
		}
			
		if($json){
			//$_html = create_cate_array($_rows,$cateid,$nid);
			$_html = ch_json_encode($_rows);
		}else{
			$_html = create_top_html($_rows,0,$nid,$delim,'',$aclass,$lclass,$idclass);
		}
		
		$str = <<<str
<?php
			\$_pos = '{$_html}';
			echo \$_pos;
        ?>
str;
		return $str;
	}
	
	//栏目标签
	public function _category ($attr, $content) {
		
		$attr    = $this->parseXmlAttr($attr,'category');
		$childs  = isset($attr['childs']) ? $attr['childs']  : 1 ;
		$hover   = isset($attr['hover'])  ? $attr['hover']   : false ;
		$isnav   = isset($attr['isnav'])  ? $attr['isnav']   : false ;
		$json    = isset($attr['json'])   ? $attr['json']    : false ;
		$delim   = isset($attr['delim'])  ? $attr['delim']   : false ;
		$limit   = isset($attr['limit'])  ? $attr['limit']   : "" ;
		$aclass  = isset($attr['aclass']) ? $attr['aclass']  : "" ;
		$lclass  = isset($attr['lclass']) ? $attr['lclass']  : "" ;
		$idclass = isset($attr['idclass'])? $attr['idclass'] : "" ;
		$module  = MODULE_NAME ;
		$module  = isset($attr['module']) ? $attr['module']: $module;
		$lang    = isset($attr['lang'])   ? $attr['lang']  : getLang();
		$cate    = I("param.cateid",0,"intval");
		$cateid  = isset($attr['cateid']) ? $attr['cateid']: $cate;
		
		if($module=="all"){
			$lists  = F('cate_'.$lang);
			//dump($lists);
			$action = "" ;
			//$cateid = $cate;
		}else{
			$lists  = F('cate_'.$lang.$module);
			$action = isset($attr['action']) ? $attr['action'] : "" ;
		}
		//是否需要找到当前栏目的根栏目
		if($hover){
			$nid = sonFindFather($cateid) ;
			if(empty($nid)){
				foreach($lists as $v){
					if(($v['level']==1) && ($v['pid']==0)){
						$nid = $v["id"];break;
					}
				}
			}
		}else{
			$nid = $cate ;
		}
		
		//是否读取所有的子节点
		$_rows = array();
		if($childs==1){
			$_rows = $lists ;
		}else{
			$_i  = 0 ;
			foreach($lists as $v){
				if($v['pid']==$cateid){
					$_rows[] = $v ; $_i++ ;
					if($limit){
						if($_i>=$limit)break;
					}
				}
			}
		}
		if($isnav){
			$_trows = array();
			foreach($_rows as $k=>$v){
				if($v['isnav'] == $isnav){
					$_trows[$k] = $v ;
				}
			}
		}else{
			$_trows = $_rows ;
		}
		
		if($json){
			$_html = create_cate_array($_trows,$cateid,$nid);
			$_html = ch_json_encode($_html);
			//json = JSON.parse(json); 
		}else{
			$_html = create_cate_html($_trows,$cateid,$nid,$delim,$action,$aclass,$lclass,$idclass);
		}
		$str = <<<str
<?php
			\$_pos = '{$_html}';
			echo \$_pos;
        ?>
str;
		return $str;
	}
	
	//级别栏目标签
	public function _levelcates($attr, $content) {
		
		$attr    = $this->parseXmlAttr($attr,'levelcates');
		$level   = isset($attr['level'])  ? $attr['level']   : 1;
		$json    = isset($attr['json'])   ? $attr['json']    : false ;
		$delim   = isset($attr['delim'])  ? $attr['delim']   : false ;
		$limit   = isset($attr['limit'])  ? $attr['limit']   : "" ;
		$aclass  = isset($attr['aclass']) ? $attr['aclass']  : "" ;
		$lclass  = isset($attr['lclass']) ? $attr['lclass']  : "" ;
		$idclass = isset($attr['idclass'])? $attr['idclass'] : "" ;
		
		$module  = MODULE_NAME ;
		$module  = isset($attr['module']) ? $attr['module']: $module;
		$lang    = isset($attr['lang'])   ? $attr['lang']  : getLang();

		$cateid  = I("param.cateid",0,"intval");
		$cateid  = isset($attr['cateid']) ? $attr['cateid']: $cateid;
		$lists   = F('cate_'.$lang.$module);
		
		$flag    = true ;
		$_rows   = array();
		if(($level == 1) || ($cateid == 0)){
			$cateid = 0;
		}else{
			$_nrows = array();
			foreach($lists as $k){
				if($k['id'] == $cateid){
					$_nrows = $k;
				}
			}
			
			if($_nrows['level'] >= $level){
				$cateid = sonFindFatherByMap($cateid,array("level"=>($level-1)));
			}else{
				$flag   = false;
				$cates  = fatherFindChilds($cateid);
				$cates .= "|,".$cates.",";
				foreach($lists as $v){
					$find = ",".$v['id'].",";
					if(strpos($cates,$find) && ($v['level'] == $level)){
						$_rows[] = $v ;
					}
				}
			}
		}
		
		//如果当前cateid
		if($flag){
			foreach($lists as $v){
				if($v['pid']==$cateid){
					$_rows[] = $v ;
				}
			}
		}
		
		if($json){
			$html = json_encode($_rows);
		}else{
			$action = isset($attr['action']) ? $attr['action'] : "" ;
			$html   = '' ;$i    = 0 ;
			foreach($_rows as $v){
				if($i&&$delim){
					$html .= '<li class="line">&nbsp;</li>';
				}
				$url = create_front_url($v,$action);
				$lc  = empty($lclass) ? "" : $lclass.$v['level'] ;
				$idc = empty($idclass)? "" : $idclass.$v['id']   ;
				
				$html .= '<li class="link '.$aclass.$lc.'" id="'.$idc.'">
					      <a href="'.$url.'" title="'.$v["title"].'" >'.$v["title"].'</a>';
	
				$i++;
				$html .= '</li>';
			}
			if($html){
				$html = '<ul>'.$html.'</ul>';
			}
		}
		
		$_html = $html;
		$str   = <<<str
<?php
			\$_pos = '{$_html}';
			echo \$_pos;
        ?>
str;
		return $str;
	}
     
    //当前所在分类位置
	public function _position ($attr,$content) {
		$attr    = $this->parseXmlAttr($attr,'position');
		$cateid  = I("param.cateid",0,"intval");
		$cateid  = isset($attr['cateid'])  ? $attr['cateid'] : $cateid;
		$action  = isset($attr['action'])  ? $attr['action'] : "";
		
		if(empty($cateid)){
			$module  = MODULE_NAME ;
			$module  = isset($attr['module']) ? $attr['module']: $module;
			$lang    = isset($attr['lang'])   ? $attr['lang']  : getLang();
			$lists   = F('cate_'.$lang.$module);
			foreach($lists as $v){
				if(($v['level']==1) && ($v['pid']==0) && ($module==$v['module'])){
					$cateid = $v['id'];break;
				}
			}
		}
		
		$class   = isset($attr['class'])   ? $attr['class']  : "icon-angle-right";
		$_html   = get_cate_position($cateid,$class,$cateid,$action);
		
		$_home   = '<li><i class="icon-home"></i><a href="'.U("Index/index","cateid=0").'">
					'.L('cfg_page_home').'</a></li>
            		<li><i class="'.$class.'"></i></li>';
		//exit($cateid);
		$str = <<<str
<?php
			\$_pos = '{$_home}'.'{$_html}';
			echo \$_pos;
        ?>
str;
		return $str;
	}
     
    
     //上一篇
     public function _prev($attr,$content) {
     	
     	$attr   = $this->parseXmlAttr($attr,'prev');
     	$id     = I("param.id",0,"intval");
     	$cateid = I("param.cateid",0,"intval");
     	if (!$id) {
			$this->error(L('cfg_form_tipmsg_illgel'));
		}
        $module  = MODULE_NAME ;
		$module  = isset($attr['module']) ? $attr['module']: $module;
		$lang    = isset($attr['lang'])   ? $attr['lang']  : getLang();
		$action  = isset($attr['action']) ? $attr['action']: "detail";
		
     	$where = "isdel=2 ";
      	if($lang != "all"){
      		$where .= "and lang='$lang' ";
      	}
      	
      	$cateid  = I("param.cateid",0,"intval");
      	$cateid  = isset($attr['cateid'])  ? $attr['cateid'] : $cateid;
      	if($cateid){
      		$_cateids = fatherFindChilds($cateid);
      		$where   .= "and cateid in($_cateids) ";
      	}

		$orderby = isset($attr['orderby']) ? $attr['orderby'] : 'id asc' ;
		$tipinfo = L('cfg_list_itf_pre_no');
        
     	$str = <<<str
<?php
			\$module  = '{$module}';
			\$where   = "{$where}";
			\$orderby = "{$orderby}";
			\$id      =  {$id};
			\$tipinfo = "{$tipinfo}";
			
			\$where .= ' and id>'.\$id;
			\$prev   = M('$module')->where(\$where)->field('id,title')->order(\$orderby)->find();
			\$prev   = empty(\$prev['id']) ? \$tipinfo : '<a href="__URL__/{$action}/id/'.\$prev['id'].'/cateid/{$cateid}">'.\$prev['title'].'</a>';
			echo \$prev;
		?>
str;
		return $str;
     }
     
     //下一篇
     public function _next($attr,$content) {
     	$attr   = $this->parseXmlAttr($attr,'prev');
     	$id     = I("param.id",0,"intval");
     	$cateid = I("param.cateid",0,"intval");
     	if (!$id) {
			$this->error(L('cfg_form_tipmsg_illgel'));
		}
        $module  = MODULE_NAME ;
		$module  = isset($attr['module']) ? $attr['module']: $module;
		$lang    = isset($attr['lang'])   ? $attr['lang']  : getLang();
		$action  = isset($attr['action']) ? $attr['action']: "detail";
		
     	$where = "isdel=2 ";
      	if($lang != "all"){
      		$where .= "and lang='$lang' ";
      	}
      	
      	$cateid  = I("param.cateid",0,"intval");
      	$cateid  = isset($attr['cateid'])  ? $attr['cateid'] : $cateid;
      	if($cateid){
      		$_cateids = fatherFindChilds($cateid);
      		$where   .= "and cateid in($_cateids) ";
      	}
		
		$orderby = isset($attr['orderby']) ? $attr['orderby'] : 'id desc' ;
		$tipinfo = L('cfg_list_itf_next_no');
        
     	$str = <<<str
<?php
			\$module  = '{$module}';
			\$where   = "{$where}";
			\$orderby = "{$orderby}";
			\$id      =  {$id};
			\$tipinfo = "{$tipinfo}";
			
			\$where .= ' and id<'.\$id;
			\$prev   = M('$module')->where(\$where)->field('id,title')->order(\$orderby)->find();
			\$prev   = empty(\$prev['id']) ? \$tipinfo : '<a href="__URL__/{$action}/id/'.\$prev['id'].'/cateid/{$cateid}">'.\$prev['title'].'</a>';
			echo \$prev;
		?>
str;
		return $str;
     }

     
     //列表页专用标签 list
	 public function _list($attr,$content) {
		$attr    = $this->parseXmlAttr($attr,'list');
			
		$module  = MODULE_NAME ;
		$module  = isset($attr['module']) ? $attr['module']: $module;
		$lang    = isset($attr['lang'])   ? $attr['lang']  : getLang();
		
      	$swhe    = isset($attr['where'])  ? $attr['where'] : "";
      	if($swhe){
      		$where   = $swhe ;
      	}else{
      		$where   = "isdel=2 ";
      		$cateid  = I("param.cateid",0,"intval");
      		$cateid  = isset($attr['cateid'])  ? $attr['cateid'] : $cateid;
      		if($cateid){
      			$_cateids = fatherFindChilds($cateid);
      			$where   .= "and cateid in($_cateids) ";
      		}
      	}
		if($lang != "all"){
			$where .= "and lang='$lang' ";
		}
		
		$single     = isset($attr['single'])     ? $attr['single']     : 'single' ;
		$titlelen   = isset($attr['titlelen'])   ? $attr['titlelen']   : '30'  ;
		$infolen    = isset($attr['infolen'])    ? $attr['infolen']    : '120' ;
		$timeformat = isset($attr['timeformat']) ? $attr['timeformat'] :  0    ;
		$thumb      = isset($attr['thumb'])      ? $attr['thumb']      :  0    ;
		$orderby    = isset($attr['orderby'])    ? $attr['orderby']    : 'id desc' ;
		$pagesize   = isset($attr['pagesize'])   ? $attr['pagesize']   :  C('web_admin_pagenum') ;
		$imgheight  = isset($attr['imgheight'])  ? $attr['imgheight']  : 0;
		$imgwidth   = isset($attr['imgwidth'])   ? $attr['imgwidth']   : 0;
		$nowPage    = I("p",1,"intval");

		$key     = md5($module.$where.$orderby.$pagesize.$nowPage);
		$path    = DATA_PATH."/$module/";
		$nofield = "content";
		
		$str = <<<str
<?php
			\$key     	 = "{$key}";
			\$path     	 = "{$path}";
			\$module     = "{$module}";
			\$where      = "{$where}";
			\$titlelen   =  {$titlelen};
			\$infolen    =  {$infolen};
			\$timeformat = '{$timeformat}';
			\$orderby    = "{$orderby}";
			\$pagesize   = {$pagesize};
			\$thumb      = {$thumb};
			
			import('ORG.Util.Page');
			\$count = M('$module')->where(\$where)->order(\$orderby)->count();
			\$Page = new Page(\$count,\$pagesize);
			\$show = \$Page->show();

			\$list = F("$module/$key");
      		if(empty(\$list)){
      			\$list = M('$module')->where(\$where)->field('$nofield',true)->order(\$orderby)->limit(\$Page->firstRow.','.\$Page->listRows)->select();
      			F("$key",\$list,'$path');
      		}
			\$str = "";
			
			foreach(\$list as \$v) :
			extract(\$v);
			if(\$titlelen) {
				\$title = sub_str(\$title,\$titlelen);
			}
			if(\$infolen) {
				\$description = sub_str(\$description,\$infolen);
			}
			if(\$timeformat) {
				\$addtime = date(\$timeformat,\$addtime);
			} else {
				\$addtime = date("Y:m:d H:i:s",\$addtime);
			}
			if(\$thumb == 1) {
				\$single = find_resource(\$v['solevar'],'{$single}',$imgwidth,$imgheight,1,'{$module}');
			}
		?>
str;
        $str .= $content;
        $str .= '<?php endforeach;?>';
        return $str;
      }
      
      //产品列表页专用标签  product
      public function _product($attr,$content) {
      	$attr    = $this->parseXmlAttr($attr,'product');
      		
      	$table   = "Product";
      	$lang    = isset($attr['lang'])   ? $attr['lang']  : getLang();
      	$status  = isset($attr['status']) ? $attr['status']: '' ;
      	$normal  = isset($attr['normal']) ? $attr['normal']: 1 ;
      	$module  = isset($attr['module']) ? $attr['module']: '' ;
      	$where = "isdel=2 ";
      	if($lang != "all"){
      		$where .= "and lang='$lang' ";
      	}      	
      	//$where .= " and normal=$normal ";
      	if($status){
      		$where .= "and status=$status ";
      	}
      	if($module){
      		$where .= "and module='$module' ";
      	}
      
      	$cateid  = I("param.cateid",0,"intval");
      	$cateid  = isset($attr['cateid'])  ? $attr['cateid'] : $cateid;
      	if($cateid){
      		$_cateids = fatherFindChilds($cateid);
      		$where   .= "and cateid in($_cateids) ";
      	}
      	
      	$single     = isset($attr['single'])     ? $attr['single']     : 'single' ;
      	$titlelen   = isset($attr['titlelen'])   ? $attr['titlelen']   : '30'  ;
      	$infolen    = isset($attr['infolen'])    ? $attr['infolen']    : '120' ;
      	$timeformat = isset($attr['timeformat']) ? $attr['timeformat'] : 0     ;
      	$thumb      = isset($attr['thumb'])      ? $attr['thumb']      : 0     ;
      	$orderby    = isset($attr['orderby'])    ? $attr['orderby']    : 'id desc' ;
      	$pagesize   = isset($attr['pagesize'])   ? $attr['pagesize']   : C('web_admin_pagenum') ;
      	$imgheight  = isset($attr['imgheight'])  ? $attr['imgheight']  : 0;
      	$imgwidth   = isset($attr['imgwidth'])   ? $attr['imgwidth']   : 0;
      	$nowPage    = I("p",1,"intval");
      	
      	$key     = md5($where.$orderby.$pagesize.$nowPage);
      	$path    = DATA_PATH."/Product/";
      	$nofield = "content";
      
      	$str = <<<str
<?php
			\$key     	 = "{$key}";
			\$path     	 = "{$path}";
			\$table      = "{$table}";
			\$where      = "{$where}";
			\$titlelen   =  {$titlelen};
			\$infolen    =  {$infolen};
			\$timeformat = '{$timeformat}';
			\$orderby    = "{$orderby}";
			\$pagesize   =  {$pagesize};
			\$thumb      =  {$thumb};
		
			import('ORG.Util.Page');
			\$count = M('$table')->where(\$where)->order(\$orderby)->count();
			\$Page  = new Page(\$count,\$pagesize);
			\$show  = \$Page->show();
      		
			\$list = F("Product/$key");
      		if(empty(\$list)){
      			\$list = M('$table')->where(\$where)->field('$nofield',true)->order(\$orderby)->limit(\$Page->firstRow.','.\$Page->listRows)->select();
      			F("$key",\$list,'$path');
      		}
			
			\$str = "";
			if(empty(\$list)){
      			echo "no product data";
      		}
			foreach(\$list as \$v) :
			extract(\$v);
			if(\$titlelen) {
				\$title = sub_str(\$title,\$titlelen);
			}
			if(\$infolen) {
				\$description = sub_str(\$description,\$infolen);
			}
			if(\$timeformat) {
				\$addtime = date(\$timeformat,\$addtime);
			} else {
				\$addtime = date("Y:m:d H:i:s",\$addtime);
			}
			if(\$thumb == 1) {
				\$single = find_resource(\$v['solevar'],'{$single}',$imgwidth,$imgheight,1,'{$table}');
			}
		?>
str;
      	$str .= $content;
      	$str .= '<?php endforeach;?>';
      	return $str;
      }
      
      
      //产品列表页专用标签  product
      public function _flagproduct($attr,$content) {
      	$attr    = $this->parseXmlAttr($attr,'flagproduct');
      		
      	$table   = "Product";
      	$lang    = isset($attr['lang'])   ? $attr['lang']  : getLang();
      	$status  = isset($attr['status']) ? $attr['status']: '' ;
      	$normal  = isset($attr['normal']) ? $attr['normal']: 1 ;
      	$module  = isset($attr['module']) ? $attr['module']: '' ;

      	$where = "isdel=2 ";
      	if($lang != "all"){
      		$where .= "and lang='$lang' ";
      	}
      	
      	$where .= "and type=1 ";
      	if($status){
      		$where .= "and status=$status ";
      	}
      	if($module){
      		$where .= "and module='$module' ";
      	}
      
      	$cateid  = I("param.cateid",0,"intval");
      	$cateid  = isset($attr['cateid'])  ? $attr['cateid'] : $cateid;
      	if($cateid){
      		$_cateids = fatherFindChilds($cateid);
      		$where   .= "and cateid in($_cateids) ";
      	}
      	
      	$single     = isset($attr['single'])     ? $attr['single']     : 'single' ;
      	$titlelen   = isset($attr['titlelen'])   ? $attr['titlelen']   : '30'  ;
      	$infolen    = isset($attr['infolen'])    ? $attr['infolen']    : '120' ;
      	$timeformat = isset($attr['timeformat']) ? $attr['timeformat'] : 0     ;
      	$thumb      = isset($attr['thumb'])      ? $attr['thumb']      : 0     ;
      	$orderby    = isset($attr['orderby'])    ? $attr['orderby']    : 'id desc' ;
      	$limit      = isset($attr['limit'])      ? $attr['limit']      : C('web_admin_pagenum') ;
      	$imgheight  = isset($attr['imgheight'])  ? $attr['imgheight']  : 0;
      	$imgwidth   = isset($attr['imgwidth'])   ? $attr['imgwidth']   : 0;
      	
      	$key     = md5($where.$orderby.$limit);
      	$path    = DATA_PATH."/Product/";
      	$nofield = "content";
      
      	$str = <<<str
<?php
			\$key     	 = "{$key}";
			\$path     	 = "{$path}";
			\$table      = "{$table}";
			\$where      = "{$where}";
			\$titlelen   =  {$titlelen};
			\$infolen    =  {$infolen};
			\$timeformat = '{$timeformat}';
			\$orderby    = "{$orderby}";
			\$pagesize   =  {$limit};
			\$thumb      =  {$thumb};
			\$imgwidth   =  {$imgwidth};
			\$imgheight  =  {$imgheight};
			
			
			\$_list = F("Product/$key");
      		if(empty(\$_list)){
      			\$_list = M('$table')->where(\$where)->field('$nofield',true)->order(\$orderby)->limit(\$pagesize)->select();
      			F("$key",\$_list,'$path');
      		}
			\$str = "";
			foreach(\$_list as \$v) :
			extract(\$v);
			if(\$titlelen) {
				\$title = sub_str(\$title,\$titlelen);
			}
			if(\$infolen) {
				\$description = sub_str(\$description,\$infolen);
			}
			if(\$timeformat) {
				\$addtime = date(\$timeformat,\$addtime);
			} else {
				\$addtime = date("Y:m:d H:i:s",\$addtime);
			}
			if(\$thumb == 1) {
				\$single = find_resource(\$v['solevar'],'{$single}',$imgwidth,$imgheight,1,'{$table}');
			}
		?>
str;
      	$str .= $content;
      	$str .= '<?php endforeach;?>';
      	return $str;
      }
      
      
      //团购和秒杀标签
      public function _activity($attr,$content) {
      	$attr    = $this->parseXmlAttr($attr,'activity');
      	
      	$view    = "GroupouView";
      	$lang    = isset($attr['lang'])   ? $attr['lang']  : getLang();
      	$single  = isset($attr['single']) ? $attr['single']: 'single' ;
      	$view    = isset($attr['view'])   ? $attr['view']  : $view ;
      	
      	$where = "isdel=2 ";
      	if($lang != "all"){
      		$where .= "and lang='$lang' ";
      	}
      	
		$now = time();
      	if($view == "SeckillView"){
      		$where .= "and ismiao=1" ;
      		//$map['begintime'] = array("GT",$now-60*10) ;
      	}else{
      		$where .= "and istuan=1" ;
      		//$map['begintime'] = array("LT",$now) ;
      		//$map['endtime']   = array("GT",$now) ;	
      	}
      	$orderby = "sort desc";
      	$module  = "Admin://".$view;
          
      	$titlelen   = isset($attr['titlelen'])   ? $attr['titlelen']   : '30'  ;
      	$infolen    = isset($attr['infolen'])    ? $attr['infolen']    : '120' ;
      	$timeformat = isset($attr['timeformat']) ? $attr['timeformat'] : 0     ;
      	$thumb      = isset($attr['thumb'])      ? $attr['thumb']      : 0     ;
      	$orderby    = isset($attr['orderby'])    ? $attr['orderby']    : $orderby ;
      	$pagesize   = isset($attr['pagesize'])   ? $attr['pagesize']   : C('web_admin_pagenum') ;
      	$imgheight  = isset($attr['imgheight'])  ? $attr['imgheight']  : 0;
      	$imgwidth   = isset($attr['imgwidth'])   ? $attr['imgwidth']   : 0;
      
      	$str = <<<str
<?php
			\$module     = "{$module}";
			\$where      = "{$where}";
			\$titlelen   = {$titlelen};
			\$infolen    = {$infolen};
			\$timeformat = '{$timeformat}';
			\$orderby    = "{$orderby}";
			\$pagesize   = {$pagesize};
			\$thumb      = {$thumb};
      
			import('ORG.Util.Page');
			\$count = D('$module')->where(\$where)->order(\$orderby)->count();
			\$Page = new Page(\$count,\$pagesize);
			\$show = \$Page->show();
      
			\$list = D('$module')->where(\$where)->order(\$orderby)->limit(\$Page->firstRow.','.\$Page->listRows)->select();
			\$str = "";
			foreach(\$list as \$v) :
			extract(\$v);
			if(\$titlelen) {
				\$title = sub_str(\$title,\$titlelen);
			}
			if(\$infolen) {
				\$description = sub_str(\$description,\$infolen);
			}
			if(\$timeformat) {
				\$addtime = date(\$timeformat,\$addtime);
			} else {
				\$addtime = date("Y:m:d H:i:s",\$addtime);
			}
			if(\$thumb == 1) {
				\$single = find_resource(\$v['solevar'],'{$single}',$imgwidth,$imgheight,1,'Product');
			}
		?>
str;
      	$str .= $content;
      	$str .= '<?php endforeach;?>';
      	return $str;
      }
      
      
      //标记列表页专用标签 flaglist
      public function _flaglist($attr,$content) {
      	$attr    = $this->parseXmlAttr($attr,'flaglist');
      		
      	$module  = MODULE_NAME ;
		$module  = isset($attr['module']) ? $attr['module']: $module;
		$lang    = isset($attr['lang'])   ? $attr['lang']  : getLang();
      	
      	$swhe    = isset($attr['where'])  ? $attr['where'] : "";
      	if($swhe){
      		$where   = $swhe ;
      	}else{
      		$where   = "isdel=2 ";
      		$cateid  = I("param.cateid",0,"intval");
      		$cateid  = isset($attr['cateid'])  ? $attr['cateid'] : $cateid;
      		if($cateid){
      			$_cateids = fatherFindChilds($cateid);
      			$where   .= "and cateid in($_cateids) ";
      		}
      	}
      	if($lang != "all"){
      		$where .= "and lang='$lang' ";
      	}
		
		$single     = isset($attr['single'])     ? $attr['single']     : 'single' ;
		$titlelen   = isset($attr['titlelen'])   ? $attr['titlelen']   : '30'  ;
		$infolen    = isset($attr['infolen'])    ? $attr['infolen']    : '120' ;
		$timeformat = isset($attr['timeformat']) ? $attr['timeformat'] :  0    ;
		$thumb      = isset($attr['thumb'])      ? $attr['thumb']      :  0    ;
		$orderby    = isset($attr['orderby'])    ? $attr['orderby']    : 'id desc' ;
		$limit      = isset($attr['limit'])      ? $attr['limit']      :  C('web_admin_pagenum') ;
		$imgheight  = isset($attr['imgheight'])  ? $attr['imgheight']  : 0;
		$imgwidth   = isset($attr['imgwidth'])   ? $attr['imgwidth']   : 0;
		
		$key     = md5($module.$where.$orderby.$limit);
		$path    = DATA_PATH."/$module/";
		$nofield = "content";
		
		$str = <<<str
<?php
			\$key     	 = "{$key}";
			\$path     	 = "{$path}";
			\$module     = "{$module}";
			\$where      = "{$where}";
			\$titlelen   =  {$titlelen};
			\$infolen    =  {$infolen};
			\$timeformat = '{$timeformat}';
			\$orderby    = "{$orderby}";
			\$pagesize   =  {$limit};
			\$thumb      =  {$thumb};
			\$imgwidth   =  {$imgwidth};
			\$imgheight  =  {$imgheight};
     
			\$_list = F("$module/$key");
      		if(empty(\$_list)){
      			\$_list = M('$module')->where(\$where)->field('$nofield',true)->order(\$orderby)->limit(\$pagesize)->select();
      			F("$key",\$_list,'$path');
      		}
			foreach(\$_list as \$v) :
			extract(\$v);
		
			if(\$titlelen) {
				\$title = sub_str(\$title,\$titlelen);
			}
			if(\$infolen) {
				\$description = sub_str(\$description,\$infolen);
			}
			if(\$timeformat) {
				\$addtime = date(\$timeformat,\$addtime);
			} else {
				\$addtime = date("Y:m:d H:i:s",\$addtime);
			}
			if(\$thumb == 1) {
				\$single = find_resource(\$v['solevar'],'{$single}',$imgwidth,$imgheight,1,'{$module}');
			}
		?>
str;
      	$str .= $content;
      	$str .= '<?php endforeach;?>';
        return $str;
      }
      
      //分页标签 pagelist
      public function _pagelist($attr,$content) {
      	
     	$attr   = $this->parseXmlAttr($attr,'pagelist');
      //$themes = "%upPage% %linkPage% %downPage% <div class=\"page_text\">%totalRow% %header% %nowPage%/%totalPage% <div> ";
      //$themes = htmlspecialchars_decode($themes);
     	$name   = isset($attr['themes']) ? $attr['themes']: 'default';
     	$config = C("PAGE_THEME");
     	if(array_key_exists($name, $config)){
     		$page  = $config[$name];
     	}else{
     		$name  ='default';
     		$page  = $config[$name];
     	}
     	
        $info = L("cfg_list_itf_recordnum");
        $fist = L("cfg_list_itf_first");
        $last = L("cfg_list_itf_last");
        $str = <<<str
<?php
		//传递参数 search=key&name=thinkphp
		\$themes = "{$name}";
        \$Page->parameter = '';
        \$Page->setConfig('header', '{$info}');
        \$Page->setConfig('first',  '{$fist}');
        \$Page->setConfig('last',   '{$last}');
        if(\$themes){
        	\$Page->setConfig('theme',  '{$page}');
      	}
        \$page = \$Page->show();
		echo \$page;
		?>
str;
		$str .= $content;
		return $str;
      }
      
      //自定义模块标签 block
      public function _block($attr,$content) {
      	$attr = $this->parseXmlAttr($attr,'block');
      	$key  = isset($attr['key']) ? $attr['key'] : '' ;
      	if(empty($key)){
      		exit("Block Key must input");
      	}
      	$lang   = isset($attr['lang']) ? $attr['lang'] : getLang();
      	$values = F("Block/".$key);
      	$value  = $values[$lang];

      	$str = <<<str
<?php
			\$value = "{$value}";
			echo htmlspecialchars_decode(\$value);
		?>
str;
      	return $str;
		
      }
       
      //广告标签
      public function _admarket($attr,$content) {
      	$attr     = $this->parseXmlAttr($attr,'admarket');
      	$cateid   = I("param.cateid",0,"intval");
      	$order    = "sort desc";
      	
      	$lang     = isset($attr['lang'])    ? $attr['lang']     : getLang();
      	$cateid   = isset($attr['cateid'])  ? $attr['cateid']   : $cateid;
      	$columnid = isset($attr['columnid'])? $attr['columnid'] : "";
      	$single   = isset($attr['single'])  ? $attr['single']   : 'single' ;
      	$imgheight= isset($attr['imgheight'])? $attr['imgheight']  : 0;
      	$imgwidth = isset($attr['imgwidth']) ? $attr['imgwidth']   : 0;
      	
      	$where  = "isdel=2 ";
      	if($lang != "all"){
      		$where .= "and lang='$lang' ";
      	}
      	
      	if($cateid){
      		$where .= "and admarket='$cateid'";
      	}

      	$str = <<<str
<?php
			\$imgwidth   =  {$imgwidth};
			\$imgheight  =  {$imgheight};
			
        	\$_list = M('Admarket')->where("{$where}")->order("{$order}")->limit({$attr['limit']})->select();
			foreach(\$_list as \$k=>\$v) :
			  extract(\$v);
        	  \$url    = get_front_url(\$v['url']);
        	  \$str   .= \$url;
        	  \$single = find_resource(\$v['solevar'],'{$single}',$imgwidth,$imgheight,1,'Admarket');
        	  \$str   .= \$single;
        	  
		?>
str;
      	$str .= $content;
      	$str .= '<?php endforeach;?>';
      	return $str;
      }
      
      //关联模型
      public function _relation($attr,$content) {
      	
      	$attr     = $this->parseXmlAttr($attr,'relation');
      
      	$order    = "addtime desc";
      	$module   = MODULE_NAME ;
      	$module   = isset($attr['module'])  ? $attr['module']: $module;
      	$relation = isset($attr['relation'])? $attr['relation']: 'ProductRelation';
      	$imgheight= isset($attr['imgheight'])? $attr['imgheight']  : 0;
      	$imgwidth = isset($attr['imgwidth']) ? $attr['imgwidth']   : 0;
      	
      	$lang     = isset($attr['lang'])    ? $attr['lang']     : getLang();
      	$id   	  = I("param.id",0,"intval");
      	$id   	  = isset($attr['id'])  ? $attr['id']   : $id;
      	 
      	$where  = "";
      	$tids   = M("$relation")->where("pid=".$id)->getField("tid",true);
      	if($tids){
      		$where  = "isdel=2 ";
      		$where .= "and id in(".implode(',',$tids).") ";
      	}
      	$nofield    = "content";
      	$single     = isset($attr['single'])     ? $attr['single']     : 'single' ;
		$titlelen   = isset($attr['titlelen'])   ? $attr['titlelen']   : '30'  ;
		$infolen    = isset($attr['infolen'])    ? $attr['infolen']    : '120' ;
		$timeformat = isset($attr['timeformat']) ? $attr['timeformat'] :  0    ;
		$thumb      = isset($attr['thumb'])      ? $attr['thumb']      :  0    ;
		$orderby    = isset($attr['orderby'])    ? $attr['orderby']    : 'addtime desc' ;
		$limit      = isset($attr['limit'])      ? $attr['limit']      :  C('web_admin_pagenum') ;
		
		$str = <<<str
<?php

			\$where      = "{$where}";
			\$titlelen   =  {$titlelen};
			\$infolen    =  {$infolen};
			\$timeformat = '{$timeformat}';
			\$orderby    = "{$orderby}";
			\$pagesize   =  {$limit};
			\$thumb      =  {$thumb};
     		
			if(\$where){
      			\$_list = M('$module')->where(\$where)->field('$nofield',true)->order(\$orderby)->limit(\$pagesize)->select();
			}else{
      			\$_list = array();
      		}
				foreach(\$_list as \$v) :
				extract(\$v);
			
				if(\$titlelen) {
					\$title = sub_str(\$title,\$titlelen);
				}
				if(\$infolen) {
					\$description = sub_str(\$description,\$infolen);
				}
				if(\$timeformat) {
					\$addtime = date(\$timeformat,\$addtime);
				} else {
					\$addtime = date("Y:m:d H:i:s",\$addtime);
				}
				if(\$thumb == 1) {
					 \$single = find_resource(\$v['solevar'],'{$single}',$imgwidth,$imgheight,1,'{$module}');
				}
      		
		?>
str;
      	$str .= $content;
      	$str .= '<?php endforeach;?>';
        return $str;
      }
     
     
     //单图片标签 single
     public function _single($attr,$content) {
     	
          $attr     = $this->parseXmlAttr($attr, 'single');
          $module   = MODULE_NAME ;
      	  $module   = isset($attr['module'])   ? $attr['module']: $module;
      	  $single   = isset($attr['single'])   ? $attr['single']: 'single' ;
      	  $imgheight= isset($attr['imgheight'])? $attr['imgheight']: 0;
      	  $imgwidth = isset($attr['imgwidth']) ? $attr['imgwidth'] : 0;
          
      	  $id = I("param.id",0,"intval");
          $id = isset($attr['id'])  ? $attr['id'] : $id;
          
          $str = <<<str
<?php
          \$module = {$module};
          \$row    = M(\$module)->find({$id});	
		  \$single = find_resource(\$v['solevar'],'{$single}',$imgwidth,$imgheight,1,'{$module}');
		  \$str   .= \$single;
		  ?>
str;
		  $str .= $content;
          return $str;
     }
     
     //多图片 Atlas
     public function _atlas($attr,$content) {
          $attr     = $this->parseXmlAttr($attr, 'atlas');
          $module   = MODULE_NAME ;
      	  $module   = isset($attr['module']) ? $attr['module']: $module ;
      	  $atlas    = isset($attr['atlas'])  ? $attr['atlas'] : 'atlas' ;
          
      	  $id = I("param.id",0,"intval");
          $id = isset($attr['id'])  ? $attr['id'] : $id;
      	  
          $str = <<<str
<?php
          \$module = {$module};
          \$row    = M(\$module\)->find({$id});
		  \$result = find_album(\$row['solevar'],'{$atlas}','\$module');
		  
          foreach(\$result as \$v) :
          extract(\$v);
		  ?>
str;
		  $str .= $content;
          $str .= '<?php endforeach;?>';
          return $str;
     }
     
     //自定义标签 detail
     public function _detail($attr,$content) {
     	
          $attr     = $this->parseXmlAttr($attr, 'detail');
          $module   = MODULE_NAME ;
      	  $module   = isset($attr['module']) ? $attr['module']: $module;
      	  $thumb    = isset($attr['thumb'])  ? $attr['thumb'] : 0 ;
     	  $single   = isset($attr['single']) ? $attr['single']: 'single' ;
     	  $where    = isset($attr['where'])  ? $attr['where'] : '' ;
     	  $imgheight= isset($attr['imgheight'])? $attr['imgheight']: 0;
     	  $imgwidth = isset($attr['imgwidth']) ? $attr['imgwidth'] : 0;
     	  
     	  if(empty($where)){
     	  	 $id = I("param.id",0,"intval");
     		 $id = isset($attr['id'])  ? $attr['id'] : $id ;
     		 if(empty($id)){
     			$cateid = I("param.cateid",0,"intval");
     			$cateid = isset($attr['cateid']) ? $attr['cateid'] : $cateid;
     			$where = "'cateid=$cateid'";
     		 }else{
     			$where = "'id=$id'";
     		 }
     	 }
     	$str = <<<str
<?php
          \$thumb  = {$thumb};
          \$module = {$module};
          \$where  = {$where};
          \$result = M(\$module)->where(\$where)->find();
          extract(\$result);
          if(\$thumb == 1) {
				\$single = find_resource(\$v['solevar'],'{$single}',$imgwidth,$imgheight,1,'{$module}');
		  }
		  ?>
str;
     	$str .= $content;
     	return $str;
     }
     
	 //自定义标签 title
     public function _webtitle($attr,$content) {
     	
     	 $attr     = $this->parseXmlAttr($attr, 'webtitle');
  
     	 $cateid  = I("param.cateid",0,"intval");
         $cateid  = isset($attr['cateid']) ? $attr['cateid'] : $cateid;
     	 $id      = I("param.id",0,"intval");
         $id      = isset($attr['id']) ?     $attr['id'] :     $id;
		 $module  = MODULE_NAME ;
		 $module  = isset($attr['module']) ? $attr['module']: $module;

         $lang    = getLang();
         $field   = "title";
         $webname = get_syscfig_key("webname".$lang);
         $html    = "";
         $detail  = "id='$id'";
         
         if($cateid){
         	$lists  = F('cate_'.$lang);
         	foreach($lists as $v){
         		if($v['id']==$cateid){
         			$title = $v["title"];break;
         			/* \$_category = M('Category')->where(\$where_cate)->getField('$field');
         			\$html     .= \$_category."_"; */
         		}
         	}
         }
       
         $str = <<<str
<?php
			\$where_detail = "{$detail}";
			\$webname      = "{$webname}";
			\$html         = "{$html}";
          	\$module       = "{$module}";
          	\$field        = "{$field}";
          	\$id           = "{$id}";
          	\$title        = "{$title}";
          	
          	if(\$id){
     			\$_detail  = M('$module')->where(\$where_detail)->getField('$field');
     			\$html    .= \$_detail."_";
     		}
     		if(\$title){
          		\$html     .= \$title."_";
          	}       	
     		\$html .= \$webname;
     		echo \$html
        ?>
str;
     	return $str;
     }
     
     //自定义标签 keywords
     public function _keywords($attr,$content) {
     	
     	 $attr     = $this->parseXmlAttr($attr, 'keywords');
     
     	 $cateid  = I("param.cateid",0,"intval");
         $cateid  = isset($attr['cateid']) ? $attr['cateid'] : $cateid;
     	 $id      = I("param.id",0,"intval");
         $id      = isset($attr['id']) ?     $attr['id'] :     $id;
		 $module  = MODULE_NAME ;
		 $module  = isset($attr['module']) ? $attr['module']: $module;
         
         $lang    = getLang();
         $field   = "keywords";
         $webname = get_syscfig_key("keywords".$lang);
         $html    = "";
         $detail  = "id='$id'";
         
         if($cateid){
         	$lists  = F('cate_'.$lang);
         	foreach($lists as $v){
         		if($v['id']==$cateid){
         			$title = $v["keywords"];break;
         		}
         	}
         }
       
         $str = <<<str
<?php
			\$where_detail = "{$detail}";
			\$webname      = "{$webname}";
			\$html         = "{$html}";
          	\$module       = "{$module}";
          	\$field        = "{$field}";
          	\$id           = "{$id}";
          	\$title        = "{$title}";
          	
          	if(\$id){
     			\$_detail  = M('$module')->where(\$where_detail)->getField('$field');
     			if(\$_detail){
     				\$html    .= \$_detail.",";
     			}
     		}
     		if(\$title){
          		\$html     .= \$title.",";
          	}       	
     		\$html .= \$webname;
     		echo \$html
        ?>
str;
     	return $str;
     }
     
     //自定义标签 description
     public function _description($attr,$content) {
     	
     	 $attr     = $this->parseXmlAttr($attr, 'description');
     
     	 $cateid  = I("param.cateid",0,"intval");
         $cateid  = isset($attr['cateid']) ? $attr['cateid'] : $cateid;
     	 $id      = I("param.id",0,"intval");
         $id      = isset($attr['id']) ?     $attr['id'] :     $id;
		 $module  = MODULE_NAME ;
		 $module  = isset($attr['module']) ? $attr['module']: $module;
         
         $lang    = getLang();
         $field   = "description";
         $webname = get_syscfig_key("description".$lang);
         
         $html    = "";
         $where_detail = "id='$id'";
         
         if($cateid){
         	$lists  = F('cate_'.$lang);
         	foreach($lists as $v){
         		if($v['id']==$cateid){
         			$title = $v["description"];break;
         		}
         	}
         }
       
         $str = <<<str
<?php
			\$where_detail = "{$where_detail}";
			\$webname      = "{$webname}";
			\$html         = "{$html}";
          	\$module       = "{$module}";
          	\$field        = "{$field}";
          	\$id           = "{$id}";
          	\$title        = "{$title}";
          	
          	if(\$id){
     			\$_detail  = M('$module')->where(\$where_detail)->getField('$field');
     			if(\$_detail){
     				\$html    .= \$_detail.",";
     			}
     		}
     		if(\$title){
          		\$html     .= \$title.",";
          	}       	
          	
     		\$html .= \$webname;
     		echo \$html
        ?>
str;
     	return $str;
     }
     
     //自定义标签 title
     public function _webmeta($attr,$content) {
     
     	$attr     = $this->parseXmlAttr($attr, 'webmeta');
     
     	$cateid  = I("param.cateid",0,"intval");
     	$cateid  = isset($attr['cateid']) ? $attr['cateid'] : $cateid;
     	$id      = I("param.id",0,"intval");
     	$id      = isset($attr['id']) ?     $attr['id'] :     $id;
     	$module  = MODULE_NAME ;
     	$module  = isset($attr['module']) ? $attr['module']: $module;
     	$lang    = getLang();
     	$field   = "content,id,addtime,solevar";
      //$field   = "title,description,keywords";
     	
     	$webname = get_syscfig_key("webname".$lang);
     	$descstr = get_syscfig_key("description".$lang);
     	$keystr  = get_syscfig_key("keywords".$lang);
     	
     	if($cateid){
     		$lists  = F('cate_'.$lang);
     		foreach($lists as $v){
     			if($v['id']==$cateid){
     				$webname = trim($v['title'])."_".$webname;
     				$descstr = trim($v['description']).",".$descstr;
     				$keystr  = trim($v['keywords']).",".$keystr;
     				break;
     			}
     		}
     		/* $_dcate  = M('Category')->where($where_cate)->field($field,true)->find($cateid);
     		if($_dcate){
     			$webname = $_dcate['title']."_".$webname;
     			$descstr = $_dcate['description'].",".$descstr;
     			$keystr  = $_dcate['keywords'].",".$keystr;
     		} */
     	}
     	
     	if($id){
     		$_detail = M("$module")->field($field,true)->find($id);
     		if($_detail){
     			$webname = trim($_detail['title'])."_".$webname;
     			$descstr = trim($_detail['description']).",".$descstr;
     			if($_detail['keywords']){
     				$keystr = trim($_detail['keywords']).",".$keystr;
     			}
     		}
     	}
     	 
         $str = <<<str
<?php
			\$_pos  = '<title>{$webname}</title>\n';
			\$_pos .= '<meta name="keywords" content="{$keystr}" />\n';
			\$_pos .= '<meta name="description" content="{$descstr}" />\n';
			echo \$_pos;
        ?>
str;
     	return trim($str);
     }
}